import { defineStore } from "pinia";

const useStore = defineStore("main", {
  // 所有数据持久化
  // persist: true,
  // 持久化存储插件其他配置
  persist: {
    // 修改存储中使用的键名称，默认为当前 Store的 id
    key: "PINIA_DATA",
    storage: window.localStorage,
    // 部分持久化状态的点符号路径数组，[]意味着没有状态被持久化(默认为undefined，持久化整个状态)
    // paths: ['userName'],
  },
  state: () => {
    return {
      userName: "",
      userInfo: {},
      menus: [],
      roles: [],
    };
  },
  getters: {
    getName: (state) => {
      return state.userName;
    },
    getUserInfo(state) {
      return state.userInfo;
    },
  },
  actions: {
    setName(data: string) {
      this.userName = data;
    },
    setRole(data: any) {
      this.roles = data;
    },
    setMenu(data: any) {
      this.menus = data;
    },
  },
});
export default useStore;
